package com.atguigu.springcloud.service;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

@Component
@FeignClient(value =  "CLOUD-PROVIDER-HYSTRIX-PAYMENT")
public class   FeignHysService {


    @GetMapping("/consumer/payment/hystrix/timeout/{id}")
    @HystrixCommand(fallbackMethod  =  "paymentTimeOutFallbackMethod",commandProperties  = {
            @HystrixProperty(name  =  "execution.isolation.thread.timeoutInMilliseconds",value  =  "1500")    //1.5秒钟以内就是正常的业务逻辑
    })
    public  String  paymentInfo_TimeOut(@PathVariable("id")  Integer  id){
        String  result  =  PaymentService.paymentInfo_TimeOut(id);
        return  result;
    }

    //兜底方法
    public  String  paymentTimeOutFallbackMethod(@PathVariable("id")  Integer  id){
        return  "我是消费者80，支付系统繁忙请10秒钟后再试或者自己运行出错请检查自己,(┬＿┬)";
    }
}